   	/***********************************************************************************************	
	Copyright (c) 2005 - Alf Magne Kalleland post@dhtmlgoodies.com	
	UPDATE LOG:	
	March, 10th, 2006 : Added support for a message while large image is loading	
	Get this and other scripts at www.dhtmlgoodies.com	
	You can use this script freely as long as this copyright message is kept intact.	
	***********************************************************************************************/ 
   	var activeImage = false;
	var imageGalleryLeftPos = false;
	var imageGalleryWidth = false;
	var imageGalleryObj = false;
	var maxGalleryXPos = false;
	var slideSpeed = 0;	
	var maxSpeed = 15;
	//var oldSpeed = 0;
	var direction = true; //r->l
	//var autoSpeed = 2;
	//var autoStart = false;
	var startIncSpeed = false;
	//var stop = false;
	// 2 nut tang toc //--------------------------
	function incSpeed()
	{		
		//if(stop != true)
		//{
			
			if(this.id=='portfolio-next')
			{	
				slideSpeed = -autoSpeed;	
				direction = true;
			}
			else
			{	
				slideSpeed = autoSpeed;
				direction = false;
			}
			startIncSpeed = true;
		//}
	}
	
	function endIncSpeed()
	{
		//oldSpeed = slideSpeed;		
		//slideSpeed=0;	
		
		if(this.id=='portfolio-next')
		{	
			slideSpeed = -autoSpeed;	
			direction = true;
		}
		else
		{	
			slideSpeed = autoSpeed;
			direction = false;
		}
		startIncSpeed = false;//dung qua trinh tang toc		
	}
	//2 nut stop-start //--------------------------
	/*
	function startSlide()
	{		
		stop = false;		
		if(oldSpeed == 0)
			slideSpeed = autoSpeed;
		else
			slideSpeed = oldSpeed;	
	}
	
	function stopSlide()
	{
		oldSpeed = slideSpeed;		
		slideSpeed=0;	
		stop = true;
	}
	*/
	
	//Trong thanh slide //--------------------------
	function outSlide()
	{		
		
		if(direction === true)
		{
			slideSpeed = -autoSpeed;
		}
		else
		{
			slideSpeed = autoSpeed;
		}			
	}	
	
	function moveSlide()
	{
	
		slideSpeed=0;		
	}
	//--------------------------
	function gallerySlide()
	{	
		//alert(imageGalleryObj.offsetLeft)
		//alert(imageGalleryObj.offsetLeft)
		var leftPos = imageGalleryObj.offsetLeft;		
		if(slideSpeed!==0)
		{	
			//can 1 dieu kien gi do de phan biet xem co hover tren cac nut prev next hay khong
			if(startIncSpeed===true )	
			{
				if(slideSpeed > 0 && slideSpeed < maxSpeed)
				{
					slideSpeed = slideSpeed + 0.1; //Gia toc trong 4s, len maxSpeed thi dung
				}
				if ( slideSpeed < 0 && slideSpeed > (-maxSpeed))
				{
					slideSpeed = slideSpeed - 0.1;
				}	
			}
			leftPos = leftPos + slideSpeed;	
					
			if(slideSpeed > 0 && leftPos > maxGalleryXPos + 5)
			{	
				var fItem = jQuery('#portfolio-content-content li:first-child');
				var lItem = jQuery('#portfolio-content-content li:last-child');				
				fItem.before(lItem);
				leftPos = maxGalleryXPos - (itemLength+5);
			}			
			if( slideSpeed < 0 && leftPos < -(itemLength+5))
			{				
				var fItem = jQuery('#portfolio-content-content li:first-child');
				var lItem = jQuery('#portfolio-content-content li:last-child');				
				lItem.after(fItem);
				leftPos = 5;
			}	
		}		
				
			//alert(leftPos);
		imageGalleryObj.style.left = leftPos + 'px';		
		setTimeout('gallerySlide()', 20);//Thoi gian 20/1000s thi thay doi toc do 1 lan		
	}	
	
	function showImage()
	{
		if(activeImage){
			activeImage.style.filter = 'alpha(opacity=80)';	
			activeImage.style.opacity = 0.8;
		}	
		this.style.filter = 'alpha(opacity=100)';
		this.style.opacity = 1;	
		activeImage = this;	
	}	
	
	function initSlideShow()
	{
		imageGalleryWidth = document.getElementById('portfolio-content').offsetWidth-5;
		imageGalleryObj = document.getElementById('portfolio-content-content');	
		maxGalleryXPos = imageGalleryObj.offsetLeft; 		
		//imageGalleryObj.innerHTML = listItem[1];
		//var itemlist = imageGalleryObj.innerHTML;			
		//imageGalleryObj.innerHTML = itemlist + '<div id="slideEnd"></div>';
		//imageGalleryObj.innerHTML = itemlist + itemlist + '<div id="slideEnd"></div>';
		//alert(itemLength);
		//alert(imageGalleryWidth);
		//alert(itemsLength);
		if( itemsLength > imageGalleryWidth)
		{
			if( autoStart == true)
				slideSpeed = -autoSpeed;
			//alert(document.getElementById('portfolio-prev'));		
			document.getElementById('portfolio-prev').onmousemove = incSpeed;
			document.getElementById('portfolio-prev').onmouseout = endIncSpeed;
			document.getElementById('portfolio-next').onmousemove = incSpeed;
			document.getElementById('portfolio-next').onmouseout = endIncSpeed;	
			
			//document.getElementById('portfolio-stop').onclick = stopSlide;	
			//document.getElementById('portfolio-start').onclick = startSlide;	
			
			imageGalleryObj.onmousemove =  moveSlide;
			imageGalleryObj.onmouseout = outSlide;	
					
			//imageGalleryLeftPos = imageGalleryObj.offsetLeft;
			//alert(imageGalleryLeftPos); //-5
			//alert(document.getElementById('portfolio-content').offsetWidth);//968
			//imageGalleryWidth = document.getElementById('portfolio-content').offsetWidth-5;
			//alert(imageGalleryWidth); //963
			//imageGalleryWidthz = document.getElementById('portfolio-content-content').offsetWidth-5;
			//alert(imageGalleryWidthz); //963
			
			
			//alert(maxGalleryXPos); //-5
			//minGalleryXPos = imageGalleryWidth - document.getElementById('slideEnd').offsetLeft - 38;
			//alert(document.getElementById('slideEnd').offsetLeft - 38);
			//minGalleryXPos = - document.getElementById('slideEnd').offsetLeft/2 - 5;
			//alert(document.getElementById('slideEnd').offsetLeft); 2232
			//alert(minGalleryXPos);//-1307
		}
		
		//var slideshowImages = imageGalleryObj.getElementsByTagName('IMG');		
		//for(var no=0;no<slideshowImages.length;no++){
		//	slideshowImages[no].onmouseover = showImage;			
		//}						
		gallerySlide();
	}
	